Skip to content

Add SulfurCube#equipItem#14062

Open
Strokkur424 wants to merge 1 commit into
PaperMC:mainfrom
Strokkur424:feat/sulfur-cube-equip-item
Open

Add SulfurCube#equipItem#14062
Strokkur424 wants to merge 1 commit into
PaperMC:mainfrom
Strokkur424:feat/sulfur-cube-equip-item

Conversation

@Strokkur424

Copy link
Copy Markdown
Member

This PR exposes the NMS-internal SulfurCube#equipItem method as an API-method.

Currently, if you want to set the item swallowed by a SulfurCube, you have to call the following code:

cube.getEquipment().setItem(
  EquipmentSlot.BODY,
  ItemType.BIRCH_LOG.createItemStack()
);

This is fine if you know about it. However that skips a little bit of logic that's inside the NMS SulfurfCube#equipItem method. Additionally, it's not intuitive for anyone simply scrolling through the SulfurCube API methods.

(Discussion: https://discord.com/channels/289587909051416579/925530366192779286/1526310872450994318)

@Strokkur424
Strokkur424 requested a review from a team as a code owner July 13, 2026 21:28
@github-project-automation github-project-automation Bot moved this to Awaiting review in Paper PR Queue Jul 13, 2026
@mbax

mbax commented Jul 13, 2026

Copy link
Copy Markdown
Member

If it isn't just a shortcut to editing the equipment I'm not sure I like it being called equipItem. Especially with the potential dropping of another item. I want some more thoughts on naming. I like SulfurCube#swallow(ItemStack)

Alternatives I thought of:

  • Engulf
  • SwallowAndMaybeBarf
  • Nom

@Doc94

Doc94 commented Jul 13, 2026

Copy link
Copy Markdown
Member

Well its based in the nms method maybe just a tryEquipItem but the original name is fine to me... (maybe can mention the events for what this method can pass?)

@lynxplay

Copy link
Copy Markdown
Contributor

I partially agree with mbax here, the method name should reflect that this is an attempt at equipping an item. I love cube.nom(ItemStack) /s. SulfurCube#attemptAbsorb / tryAbsorb / absorb would work. So would swallow. Its not really an active equipping.

Javadocs should mention that events are called.

Also unsure about the boolean return, how do I get the itemstack that was possibly dropped from the sulfur cube?


Tho the more I think about it the less convinced I am that this method is even needed in the first place. The use case for actually running the vanilla logic seem small. E.g. how often would a plugin really need to "simulate" a player actively attempting to place a block into a sulfur cube. Most of the times it'd probably be a direct set and playing the noise, which this method does not offer fine control over.
The primary motivation for adding this method seem to be related to API simplicity, which is a fair goal but that could be solved via a plain setter overload on the entity instead of exposing the vanilla method.

My thoughts for that being that this method has a lot of possibly unexpected side effects that are only exposed when reading the javadocs and that, from my perspective, most plugin developers will not be aiming for. Am a concerned that this addition will do more harm than good for a person just tab completing away SulfurCube, finding this method and then all of a sudden their items drop to the floor and a sound is playing when they were just trying to spawn in a sulfur cube with a block inside.

Introducing fine grained control over the individual actions the method does (sound playing, item dropping) would also balloon up the api surface and diff needed when most plugin developers can simply write out a single if hasBlockSwallowed() dropBlockSwallowed() before their setter if they want to do so.

@Strokkur424

Copy link
Copy Markdown
Member Author

Your concerns sound very reasonable. Based on that, would the following changes be accepted?

  • Addition of SulfurCube#setEquipped(ItemStack), with the sole purpose of silently setting the currently equipped item stack, with the goal being API simplicity.
  • Addition of ItemStack SulfurCube#getEquipped(), the appropriate getter, same use case as above.
  • Rename boolean equipItem(ItemStack) to boolean swallow(ItemStack), noting the events + logical difference to setEquipped, cross referencing both in @see Javadoc note?

@lynxplay

Copy link
Copy Markdown
Contributor

Yea I think that seems fine. The equip methods can be default in the interface and forward directly there to the correct but maybe hard to know about equipment methods using BODY slot. They should also probably explain that they are a simple alias / utility for that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Awaiting review

Development

Successfully merging this pull request may close these issues.

4 participants